package com.cloudwise.controller;

import com.cloudwise.service.PersonService;
import com.cloudwise.service.impl.PersonServiceImpl;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

/**
 * @author ：Teacher陈（86521760@qq.com）
 * @date ：Created in 2023/2/16 9:43
 * @description：删除人员
 * @modified By：
 * @version: 1.0
 */
@WebServlet(name = "DeletePerson",value = "/deletePerson")
public class DeletePerson extends HttpServlet {
    PersonService personService = new PersonServiceImpl();
    @Override
    protected void service(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        //1、将人员的编号，传入后端，后端接口根据编号，去数据库中删除对应的数据。
            //1.1 获取人员编号
        String personId = req.getParameter("personId");
        System.out.println("获取的人员id："+personId);
            //1.2 根据编号删除数据
        boolean deletePersonById = personService.deletePersonById(personId);
        if(deletePersonById){
            //2、删除成功之后，重新查询数据并刷新页面。
            String contextPath = req.getContextPath();
            resp.sendRedirect(contextPath+"/person");
        }else{
            //3、删除失败，去失败页面。
            resp.sendRedirect("error.jsp");
        }

    }
}
